#include "kernel/ae.hpp"
#include "yocto/lua/lua-config.hpp"



AE:: AE( lua_State *L ) :
Enzyme( L, "AE", "efficiencyAE" ),
K( Lua::Config::Get<lua_Number>(L,"KAE") ),
gamma(1),
sBicarb("HCO3-"),
sCl("Cl-")
{
    std::cerr << "K_AE=" << K << std::endl;
}


AE:: ~AE() throw()
{
}


Real AE:: Sigma( const Real bicarb ) const
{
	const Real b   = Pow(bicarb,gamma);
	const Real k50 = Pow(K,gamma); 
	return (b/(k50+b));
}

BIO_PH_ENZYME_CALL(AE::)
{
	const Real bicarb = S_in[ sBicarb ];
	const Real rho    = V * Sigma( bicarb ) * efficiency(t);
	
	dS[ sBicarb ] -= rho;
	dS[ sCl     ] += rho;
	
	return rho;
}

Real AE:: omega( Real bicarb, Real h ) const
{
	const Real num = K + bicarb;
	return -V * (bicarb/h) * K / (num*num);
}

